home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / performLoft.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  14.0 KB  |  539 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  Mar 14, 1997
  22. //
  23. //  Description:
  24. //      This script is defines the option box for the loft menu item.
  25. //
  26.  
  27.  
  28. //
  29. //  Procedure Name:
  30. //      setOptionVars
  31. //
  32. //  Description:
  33. //        Initialize the option values.
  34. //
  35. //  Input Arguments:
  36. //        Whether to set the options to default values.
  37. //
  38. //  Return Value:
  39. //      None.
  40. //
  41. proc setOptionVars(int $forceFactorySettings)
  42. {
  43.     if ($forceFactorySettings || !`optionVar -exists loftUniform`) {
  44.         optionVar -intValue loftUniform 1;
  45.     }
  46.     if ($forceFactorySettings || !`optionVar -exists loftClose`) {
  47.         optionVar -intValue loftClose 0;
  48.     }
  49.     if ($forceFactorySettings || !`optionVar -exists loftAutoReverse`) {
  50.         optionVar -intValue loftAutoReverse 1;
  51.     }
  52.     if ($forceFactorySettings || !`optionVar -exists loftDegree`) {
  53.         optionVar -intValue loftDegree 3;
  54.     }
  55.     if( $forceFactorySettings || !`optionVar -exists loftRange`) {
  56.         optionVar -intValue loftRange 0;
  57.     }
  58.     if( $forceFactorySettings || !`optionVar -exists loftPolys`) {
  59.         optionVar -intValue loftPolys 0;
  60.     }
  61.     if( $forceFactorySettings || !`optionVar -exists loftSectionSpans`) {
  62.         optionVar -intValue loftSectionSpans 1;
  63.     }
  64. }
  65.  
  66. //
  67. //  Procedure Name:
  68. //      loftSetup
  69. //
  70. //  Description:
  71. //        Update the state of the option box UI to reflect the option values.
  72. //
  73. //  Input Arguments:
  74. //      parent               - Top level parent layout of the option box UI.
  75. //                             Required so that UI object names can be 
  76. //                             successfully resolved.
  77. //
  78. //        forceFactorySettings - Whether the option values should be set to
  79. //                             default values.
  80. //
  81. //  Return Value:
  82. //      None.
  83. //
  84.  
  85. global proc loftSetup( string $parent,
  86.                        int $forceFactorySettings,
  87.                        string $goToTool )
  88. {
  89.     //    Retrieve the option settings
  90.     //
  91.     setOptionVars( $forceFactorySettings );
  92.     loftToolSetup( $forceFactorySettings, $goToTool );
  93.  
  94.     setParent $parent;
  95.  
  96.     //    Query the optionVar's and set the values into the controls.
  97.  
  98.     // Query the optionVar's and set the values into the controls
  99.     //
  100.     int $uniform = `optionVar -query loftUniform`;
  101.     int $autoReverse = `optionVar -query loftAutoReverse`;
  102.     int $close = `optionVar -query loftClose`;
  103.     int $degree = `optionVar -query loftDegree`;
  104.     int $range = `optionVar -query loftRange`;
  105.     int $polys = `optionVar -q loftPolys`;
  106.     int $spans = `optionVar -query loftSectionSpans`;
  107.     if( ! `isTrue "SurfaceUIExists"` ) $polys = 1;
  108.  
  109.     // Set the controls
  110.     //
  111.     radioButtonGrp -edit -select (2 - $uniform) uniformRadio;
  112.     checkBoxGrp -edit -value1 $autoReverse autoReverseCloseCheck;
  113.     checkBoxGrp -edit -value2 $close autoReverseCloseCheck;
  114.     if( 3 == $degree ) radioButtonGrp -edit -select 2 degreeRadio;
  115.     else radioButtonGrp -edit -select 1 degreeRadio;
  116.     radioButtonGrp -edit -select ($range + 1) rangeRadio;
  117.     if( `isTrue "SurfaceUIExists"` ) {
  118.         if( (3 == $polys) && ! `isTrue "SubdivUIExists"` ) {
  119.             $polys = 2;
  120.         }
  121.         radioButtonGrp -edit -select ($polys+1) outputPolyRadioButtonGrp;
  122.     }
  123.     intSliderGrp -e -v $spans sectionSpansInt;
  124.  
  125.     switch( $polys ) {
  126.       case 0:
  127.       default:
  128.         tabLayout -e -st polyOptionsNo polyOptions;
  129.         break;
  130.       case 1:
  131.         tabLayout -e -st polyOptionsOK polyOptions;
  132.         break;
  133.       case 2:
  134.         tabLayout -e -st polyOptionsSubdiv polyOptions;
  135.         break;
  136.       case 3:
  137.         tabLayout -e -st polyOptionsBezier polyOptions;
  138.         break;
  139.     }
  140.  
  141.     if( "" != $goToTool ) { 
  142.         checkBoxGrp -e -v1 `scriptCtx -q -euc $goToTool`
  143.           scriptToolExtraWidget;
  144.         checkBoxGrp -e -v2 `scriptCtx -q -lac $goToTool`
  145.           scriptToolExtraWidget;
  146.     }
  147.  
  148.     nurbsToPolySetup( $parent, $forceFactorySettings );
  149.     nurbsToSubdivSetup( $parent, $forceFactorySettings );
  150. }
  151.  
  152. //
  153. //  Procedure Name:
  154. //      loftCallback
  155. //
  156. //  Description:
  157. //        Update the option values with the current state of the option box UI.
  158. //
  159. //  Input Arguments:
  160. //      parent - Top level parent layout of the option box UI.  Required so
  161. //               that UI object names can be successfully resolved.
  162. //
  163. //        doIt   - Whether the command should execute.
  164. //
  165. //  Return Value:
  166. //      None.
  167. //
  168.  
  169. global proc loftCallback(string $parent, int $doIt, string $goToTool)
  170. {
  171.     if( "" != $goToTool ) {
  172.         optionVar -iv loftEuc `scriptCtx -q -euc $goToTool`;
  173.         optionVar -iv loftLac `scriptCtx -q -lac $goToTool`;
  174.     }
  175.     setParent $parent;
  176.  
  177.     // Set the optionVar's from the current control values, and then perform 
  178.     // the command
  179.     //
  180.     int $uniform = 2 - `radioButtonGrp -q -select uniformRadio`;
  181.     int $autoReverse = `checkBoxGrp -query -v1 autoReverseCloseCheck`;
  182.     int $close = `checkBoxGrp -query -v2 autoReverseCloseCheck`;
  183.     int $degree = `radioButtonGrp -q -select degreeRadio`;
  184.     int $spans = `intSliderGrp -q -v sectionSpansInt`;
  185.     if( 1 != $degree ) $degree = 3;
  186.     int $range = `radioButtonGrp -q -select rangeRadio` - 1;
  187.     if( `isTrue "SurfaceUIExists"` ) {
  188.         int $polygons = `radioButtonGrp -q -select outputPolyRadioButtonGrp`;
  189.         if( (3 == $polygons) && ! `isTrue "SubdivUIExists"` ) {
  190.             $polygons = 4;
  191.         }
  192.         optionVar -intValue loftPolys ($polygons-1);
  193.     }
  194.  
  195.     optionVar -intValue loftUniform $uniform;
  196.     optionVar -intValue loftClose $close;
  197.     optionVar -intValue loftAutoReverse $autoReverse;
  198.     optionVar -intValue loftDegree $degree;
  199.     optionVar -intValue loftRange $range;
  200.     optionVar -intValue loftSectionSpans $spans;
  201.  
  202.     nurbsToPolyCallback( $parent, 0 );
  203.     nurbsToSubdivCallback( $parent, 0 );
  204.  
  205.     if( 1 == $doIt ) {
  206.         performLoft( 0, $goToTool ); 
  207.         string $tmpCmd = "performLoft(0, \"" + $goToTool + "\")";
  208.         addToRecentCommandQueue $tmpCmd "Loft";
  209.     }
  210.     else if( $doIt ) {
  211.         setToolTo $goToTool;
  212.     }
  213. }
  214.  
  215. //
  216. //  Procedure Name:
  217. //      loftOptions
  218. //
  219. //  Description:
  220. //        Construct the option box UI.  Involves accessing the standard option
  221. //        box and customizing the UI accordingly.
  222. //
  223. //  Input Arguments:
  224. //      None.
  225. //
  226. //  Return Value:
  227. //      None.
  228. //
  229.  
  230. proc loftOptions( int $inTheTool, string $goToTool )
  231. {
  232.     //    Name of the command for this option box.
  233.     //
  234.     string $commandName = "loft";
  235.  
  236.     //    Build the option box actions.
  237.     //
  238.     string $callback = ($commandName + "Callback");
  239.     string $setup = ($commandName + "Setup");
  240.  
  241.     //    Step 1:  Get the option box.
  242.     //    ============================
  243.     global string $gOptionBoxActionToolItem;
  244.     $gOptionBoxActionToolItem = "modelWithToolLoft";
  245.     global string $gOptionBoxActionToolItemCB;
  246.     $gOptionBoxActionToolItemCB = "loftToolScript 3";
  247.  
  248.     string $layout = getOptionBox();
  249.     setParent $layout;
  250.     
  251.     //    Step 2:  Pass the command name to the option box.
  252.     //    =================================================
  253.     setOptionBoxCommandName($commandName);
  254.     
  255.     //    Step 3:  Activate the default UI template.
  256.     //    ==========================================
  257.     setUITemplate -pushTemplate DefaultTemplate;
  258.  
  259.     //    Step 4: Create option box contents.
  260.     //    ===================================
  261.     
  262.     //    Turn on the wait cursor.
  263.     //
  264.     waitCursor -state 1;
  265.  
  266.     tabLayout -scr true -tv false;
  267.     
  268.     string $parent = `columnLayout -adjustableColumn 1`;
  269.     
  270.     radioButtonGrp
  271.         -numberOfRadioButtons 2
  272.         -label "Parameterization" 
  273.         -label1 "Uniform"
  274.         -label2 "Chord Length"
  275.         uniformRadio;
  276.         
  277.     checkBoxGrp -ncb 2
  278.         -l1 "Auto Reverse"
  279.         -l2 "Close"
  280.         autoReverseCloseCheck;
  281.         
  282.     radioButtonGrp -nrb 2
  283.         -l "Surface Degree"
  284.         -l1 "Linear"
  285.         -l2 "Cubic"
  286.         degreeRadio;
  287.  
  288.     intSliderGrp
  289.         -l "Section Spans"
  290.         -min 1
  291.         -max 10
  292.         -fmn 1
  293.         -fmx 500
  294.         sectionSpansInt;
  295.  
  296.     separator;
  297.  
  298.     radioButtonGrp -numberOfRadioButtons 2
  299.         -label "Curve Range"
  300.         -label1 "Complete"
  301.         -label2 "Partial"
  302.         rangeRadio;
  303.  
  304.     if( `isTrue "SubdivUIExists"` ) {
  305.         radioButtonGrp -nrb 4
  306.             -label "Output Geometry"
  307.             -label1 "Nurbs"
  308.             -label2 "Polygons"
  309.             -label3 "Subdiv"
  310.             -label4 "Bezier"
  311.             -cc1 "tabLayout -e -st polyOptionsNo polyOptions"
  312.             -cc2 "tabLayout -e -st polyOptionsOK polyOptions"
  313.             -cc3 "tabLayout -e -st polyOptionsSubdiv polyOptions"
  314.             -cc4 "tabLayout -e -st polyOptionsBezier polyOptions"
  315.           outputPolyRadioButtonGrp;
  316.     }
  317.     else if( `isTrue "SurfaceUIExists"` ) {
  318.         radioButtonGrp -nrb 3
  319.             -label "Output Geometry"
  320.             -label1 "Nurbs"
  321.             -label2 "Polygons"
  322.             -label3 "Bezier"
  323.             -cc1 "tabLayout -e -st polyOptionsNo polyOptions"
  324.             -cc2 "tabLayout -e -st polyOptionsOK polyOptions"
  325.             -cc3 "tabLayout -e -st polyOptionsBezier polyOptions"
  326.             outputPolyRadioButtonGrp;
  327.     }
  328.  
  329.     separator;
  330.  
  331.     tabLayout -tabsVisible false polyOptions;
  332.         string $par = `columnLayout polyOptionsOK`;
  333.         nurbsToPolyAddOptions $par;
  334.         setParent ..;
  335.         columnLayout polyOptionsNo;
  336.         setParent ..;
  337.         columnLayout polyOptionsSubdiv;
  338.         nurbsToSubdivAddOptions $par;
  339.         setParent ..;
  340.         columnLayout polyOptionsBezier;
  341.         setParent ..;
  342.     setParent ..;
  343.  
  344.     if( $inTheTool ) {
  345.         separator;
  346.         checkBoxGrp -ncb 2 -l "Tool Behavior"
  347.           -l1 "Exit on Completion"
  348.           -v1 off
  349.           -on1 ("scriptCtx -e -euc true " + $goToTool)
  350.           -of1 ("scriptCtx -e -euc false " + $goToTool)
  351.  
  352.           -l2 "Auto Completion"
  353.           -v2 on
  354.           -on2 ("scriptCtx -e -lac true " + $goToTool)
  355.           -of2 ("scriptCtx -e -lac false " + $goToTool)
  356.           scriptToolExtraWidget;
  357.     }
  358.  
  359.     //    Turn off the wait cursor.
  360.     //
  361.     waitCursor -state 0;
  362.     
  363.     //    Step 5: Deactivate the default UI template.
  364.     //  ===========================================
  365.     //
  366.     setUITemplate -popTemplate;
  367.  
  368.     //    Step 6: Customize the buttons.  
  369.     //    ==============================
  370.  
  371.     //    'Apply' button.
  372.     //
  373.     string $applyBtn = getOptionBoxApplyBtn();
  374.     if( $inTheTool ) {
  375.         button -edit -l "Loft Tool"
  376.           -command ($callback + " " + $parent + " 3 \"" + $goToTool + "\"")
  377.           $applyBtn;
  378.     }
  379.     else {
  380.         button -edit -l "Loft"
  381.           -command ($callback + " " + $parent + " 1 \"" + $goToTool + "\"")
  382.           $applyBtn;
  383.     }
  384.  
  385.     //    'Save' button.
  386.     //
  387.     string $saveBtn = getOptionBoxSaveBtn();
  388.     button -edit 
  389.         -command ($callback + " " + $parent + " 0 \"" +
  390.                   $goToTool + "\"; hideOptionBox")
  391.         $saveBtn;
  392.  
  393.     //    'Reset' button.
  394.     //
  395.     string $resetBtn = getOptionBoxResetBtn();
  396.     button -edit 
  397.         -command ($setup + " " + $parent + " 1 \"" + $goToTool + "\"")
  398.         $resetBtn;
  399.  
  400.     //    Step 7: Set the option box title.
  401.     //    =================================
  402.     //
  403.     if( $inTheTool ) {
  404.         setOptionBoxTitle("Loft Tool Options");
  405.     } else {
  406.         setOptionBoxTitle("Loft Options");
  407.     }
  408.  
  409.     //    Step 8: Customize the 'Help' menu item text.
  410.     //    ============================================
  411.     //
  412.     setOptionBoxHelpTag( "Loft" );
  413.  
  414.     //    Step 9: Set the current values of the option box.
  415.     //    =================================================
  416.     //
  417.     eval ($setup + " " + $parent + " 0 \"" + $goToTool + "\"");    
  418.     
  419.     //    Step 10: Show the option box.
  420.     //    =============================
  421.     //
  422.     showOptionBox();
  423. }
  424.  
  425. //
  426. //  Procedure Name:
  427. //      loftHelp
  428. //
  429. //  Description:
  430. //        Return a short description about this command.
  431. //
  432. //  Input Arguments:
  433. //      None.
  434. //
  435. //  Return Value:
  436. //      string.
  437. //
  438.  
  439. proc string loftHelp()
  440. {
  441.     return 
  442.     "  Command: Loft - loft a number of curves (or add to lofted surface)\n" +
  443.     "Selection: curve, curve on surface, surface isoparm";
  444. }
  445.  
  446. //
  447. //  Procedure Name:
  448. //      assembleCmd
  449. //
  450. //  Description:
  451. //        Construct the command that will apply the option box values.
  452. //
  453. //  Input Arguments:
  454. //      None.
  455. //
  456. //  Return Value:
  457. //      None.
  458. //
  459. proc string assembleCmd()
  460. {
  461.     string $cmd = "doPerformLoft";
  462.  
  463.     setOptionVars(false);
  464.  
  465.     int $history = `constructionHistory -q -tgl`;
  466.     int $uniform = `optionVar -q loftUniform`;
  467.     int $autoReverse = `optionVar -q loftAutoReverse`;
  468.     int $close = `optionVar -q loftClose`;
  469.     int $degree = `optionVar -q loftDegree`;
  470.     int $spans = `optionVar -q loftSectionSpans`;
  471.     int $range = `optionVar -q loftRange`;
  472.     int $polys = `optionVar -q loftPolys`;
  473.     if( ! `isTrue "SurfaceUIExists"` ) $polys = 1;
  474.  
  475.     $cmd = $cmd + "(";
  476.     $cmd = $cmd + "\"1\"" + ", {";
  477.     $cmd = $cmd + "\"" + $history + "\",";
  478.     $cmd = $cmd + "\"" + $uniform + "\",";
  479.     $cmd = $cmd + "\"" + $autoReverse + "\",";
  480.     $cmd = $cmd + "\"" + $close + "\",";
  481.     $cmd = $cmd + "\"" + $degree + "\",";
  482.     $cmd = $cmd + "\"" + $spans + "\",";
  483.     $cmd = $cmd + "\"" + $range + "\",";
  484.     $cmd = $cmd + "\"" + $polys + "\"";
  485.     $cmd = $cmd + "} )";
  486.  
  487.     return $cmd;
  488. }
  489.  
  490. //
  491. //  Procedure Name:
  492. //      performLoft
  493. //
  494. //  Description:
  495. //        Perform the loft command using the corresponding 
  496. //        option values.  This procedure will also show the option box
  497. //        window if necessary as well as construct the command string
  498. //        that will invoke the loft command with the current
  499. //        option box values.
  500. //
  501. //  Input Arguments:
  502. //      0 - Execute the command.
  503. //      1 - Show the option box dialog.
  504. //      2 - Return the command.
  505. //      3 - Show the tool option box dialog.
  506. //
  507. //  Return Value:
  508. //      None.
  509. //
  510.  
  511. global proc string performLoft(int $action, string $goToTool)
  512. {
  513.     int $inTheTool = false;
  514.     if( 3 == $action ) {
  515.         $action = 1;
  516.         $inTheTool = true;
  517.     }
  518.  
  519.     string $cmd = "";
  520.     switch ($action) {
  521.       case 0:
  522.         setOptionVars(false);
  523.         $cmd = `assembleCmd`;
  524.         eval($cmd);
  525.         break;
  526.       case 1:
  527.         loftOptions( $inTheTool, $goToTool );
  528.         break;
  529.  
  530.       case 2:
  531.       default:
  532.         setOptionVars (false);
  533.         $cmd = `assembleCmd`;
  534.         break;
  535.     }
  536.     return $cmd;
  537. }
  538.  
  539.